package com.lx.datasource;

import lombok.extern.slf4j.Slf4j;

/**
 * 数据源持有类
 *
 * @author 段誉
 * @create 2019-04-12 15:39
 */
@Slf4j
public class DataSourceContextHolder {
  private static final String DEFAULT_DATASOURCE = "PRIMARY_DATASOURCE";

  private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();

  public static void setDataSource(String dbType) {
    log.info("切换到[{}]数据源", dbType);
    contextHolder.set(dbType);
  }

  public static String getDataSource() {
    return contextHolder.get();
  }

  public static void clearDataSource() {
    contextHolder.remove();
  }
}
